import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
import loginui
from loginui import Ui_MainWindow

class LoginWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.widget_3.hide()

        # 隐藏窗口
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.show()

        self.ui.pushButton.clicked.connect(self.change_widget2)
        self.ui.pushButton_2.clicked.connect(self.change_widget3)

    # 移动窗口
    def mousePressEvent(self, event):
        if (event.button() == QtCore.Qt.LeftButton) and (self.isMaximized() == False):
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos() # 获取鼠标窗口位置
            event.accept()
            self.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))# 更改鼠标图标

    def mouseMoveEvent(self, mouse_event):
        if QtCore.Qt.LeftButton and self.m_flag:
            self.move(mouse_event.globalPos() - self.m_Position) #更改窗口位置
            mouse_event.accept()

    def mouseReleaseEvent(self, mouse_event):
        self.m_flag = False
        self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

    def change_widget2(self):
        self.ui.widget_2.show()
        self.ui.widget_3.hide()

    def change_widget3(self):
        self.ui.widget_2.hide()
        self.ui.widget_3.show()



if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = LoginWindow()
    sys.exit(app.exec_())